use std::{cell::{RefCell, Ref}, rc::Rc};

use crate::{vector::Vector3f, object::DrawableObj, light::Light, v3f};

pub struct  Scene {
    pub width: usize,
    pub height: usize,
    pub fov: f32,
    pub background_color: Vector3f,
    pub max_depth: i32,
    pub epsilon: f32,
    objects: RefCell<Vec<Rc<dyn DrawableObj>>>,
    lights: RefCell<Vec<Rc<Light>>>,
}

impl Scene {
    pub fn new(w: usize, h: usize) -> Self {
        Self {
            width: w,
            height: h,
            fov: 90.0,
            background_color: v3f!(0.235294, 0.67451, 0.843137),
            max_depth: 5,
            epsilon: 0.00001,
            objects: RefCell::new(vec![]),
            lights: RefCell::new(vec![]),
        }
    }

    pub fn add_object(&self, object: Rc<dyn DrawableObj>) {
        self.objects.borrow_mut().push(object);
    }

    pub fn add_light(&self, light: Rc<Light>) {
        self.lights.borrow_mut().push(light);
    }

    pub fn get_objects(&self) -> Ref<'_, Vec<Rc<(dyn DrawableObj + 'static)>>> {
        self.objects.borrow()
    }
    pub fn get_lights(&self) -> Ref<'_, Vec<Rc<Light>>> {
        self.lights.borrow()
    }
}